<?php
require_once PATH_SITE.'cn/royan/php/utils/Plugins.util.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once PATH_SITE.'org/puremvc/php/patterns/mediator/Mediator.php';
require_once PATH_SITE.'org/puremvc/php/interfaces/INotification.php';
/**
 * Description of ApplicationMediator
 *
 * @author Royan
 */
class ApplicationMediator extends Mediator
{
    //put your code here
    const NAME                  = "ApplicationMediator";
    
    const CONFIG_LOAD_COMPLETE  = "configLoadCompelte";
    const SAY_HELLO_TO_CLIENT   = "sayHelloToClient";

    public function __construct() {
        parent::__construct( ApplicationMediator::NAME );
    }
    
    public function listNotificationInterests()
    {
        return array( ApplicationMediator::CONFIG_LOAD_COMPLETE,
                      ApplicationMediator::SAY_HELLO_TO_CLIENT );
    }

    public function handleNotification( INotification $notification )
    {
        switch ($notification->getName())
        {
            case ApplicationMediator::CONFIG_LOAD_COMPLETE:
                $configProxy = $this->facade->retrieveProxy( ConfigProxy::NAME );
                $config = $configProxy->getData();
                Plugins::$config = $config;
                $this->sendNotification( ApplicationFacade::START_SOCKET_CONNECT, $config );
                
                break;
            
            case ApplicationMediator::SAY_HELLO_TO_CLIENT:
                $message = '<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">'.
			'<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>'."\0";
                
                $connect = $notification->getBody();
                
                $info = array( "client"=>$connect,
                               "message"=>$message,
                               "cryptable"=>FALSE );
                $this->sendNotification( ApplicationFacade::DISPATCH_CLIENT_DATA, $info );
                break;
            
            default:
                
                break;
        }
    }
}

?>
